import {Parser as Passer, parser, struct_key} from "../../config/Parser";
const fs = require("fs");

const ethers = require("ethers");
const ipfsAPI = require("ipfs-api");

const ipfs = ipfsAPI({ host: "49.234.138.61", port: "5001", protocol: "http" });
export async function saveOnIpfs(blob, call) {
  console.log("start saveOnIpfs");
  console.log("blob=", blob);
  const descBuffer = Buffer.from(blob, "utf-8");
  ipfs.add(descBuffer, (err, files) => {
    if (err || typeof files == "undefined") {
      console.log("err=" + err);
    } else {
      console.log("files=", files[0].hash);
      call(files[0].hash);
    }
  });
}



//const Web3=require('web3')
const abis =  [
  {
    "inputs": [],
    "stateMutability": "nonpayable",
    "type": "constructor"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "address",
        "name": "from",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "Sent",
    "type": "event"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "CropsDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "plantType",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "cropName",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "plantType",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      }
    ],
    "name": "addCrop",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "goodsId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "exp",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "phone",
        "type": "string"
      }
    ],
    "name": "addGoods",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      }
    ],
    "name": "addMaterial",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processName",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "types",
        "type": "uint256"
      }
    ],
    "name": "addProcess",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productType",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      }
    ],
    "name": "addProduct",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      }
    ],
    "name": "bindMaterial",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "signer",
        "type": "address"
      }
    ],
    "name": "checkSignUp",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "cropProcess",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "cropProcessDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      }
    ],
    "name": "finishProcess",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getAllUserInfo",
    "outputs": [
      {
        "components": [
          {
            "internalType": "uint256",
            "name": "role",
            "type": "uint256"
          },
          {
            "internalType": "uint256",
            "name": "requestRole",
            "type": "uint256"
          },
          {
            "internalType": "uint256",
            "name": "status",
            "type": "uint256"
          },
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "phone",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "privateData",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "userAddress",
            "type": "address"
          },
          {
            "internalType": "string",
            "name": "publicKey",
            "type": "string"
          }
        ],
        "internalType": "struct Loan.userInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "cUser",
        "type": "address"
      }
    ],
    "name": "getUserCrops",
    "outputs": [
      {
        "components": [
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "plantType",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "cropId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "time",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "note",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "produceAddress",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "materialId",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          }
        ],
        "internalType": "struct Loan.cropInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "gUser",
        "type": "address"
      }
    ],
    "name": "getUserGoods",
    "outputs": [
      {
        "components": [
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "certification",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "goodsId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "productId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "time",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "produceAddress",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "note",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "exp",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "phone",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          }
        ],
        "internalType": "struct Loan.goodsInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "mUser",
        "type": "address"
      }
    ],
    "name": "getUserMaterial",
    "outputs": [
      {
        "components": [
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          },
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "materialId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "certification",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "produceAddress",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "note",
            "type": "string"
          }
        ],
        "internalType": "struct Loan.materialInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "pUser",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "types",
        "type": "uint256"
      }
    ],
    "name": "getUserProcess",
    "outputs": [
      {
        "components": [
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "certification",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "processId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "productId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "time",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "produceAddress",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "note",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          }
        ],
        "internalType": "struct Loan.processInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "pUser",
        "type": "address"
      }
    ],
    "name": "getUserProduct",
    "outputs": [
      {
        "components": [
          {
            "internalType": "string",
            "name": "productId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "certification",
            "type": "string"
          },
          {
            "internalType": "uint256",
            "name": "status",
            "type": "uint256"
          },
          {
            "internalType": "string",
            "name": "cropId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "time",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "productType",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          }
        ],
        "internalType": "struct Loan.productInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "goodsDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "goodsId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "exp",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "phone",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "materialDict",
    "outputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "materialList",
    "outputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "owner",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "processDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "productDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "status",
        "type": "uint256"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productType",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "signer",
        "type": "address"
      }
    ],
    "name": "refuseSignUp",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "requestRole",
        "type": "uint256"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      }
    ],
    "name": "signUp",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "user",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "role",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "requestRole",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "status",
        "type": "uint256"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "phone",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "privateData",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "userAddress",
        "type": "address"
      },
      {
        "internalType": "string",
        "name": "publicKey",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userCrops",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "plantType",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userGoods",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "goodsId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "exp",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "phone",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userMaterial",
    "outputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userProcess",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userProduct",
    "outputs": [
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "status",
        "type": "uint256"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productType",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "userRole",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  }
];
//const contractAddress = "0x3acc15dE35aaB8A94B7D2426E27c887541e4DE6c";
const contractAddress = "0xD833215cBcc3f914bD1C9ece3EE7BF8B14f841bb";
const abi=[
  {
    "inputs": [],
    "stateMutability": "nonpayable",
    "type": "constructor"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "address",
        "name": "from",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "Sent",
    "type": "event"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "CropsDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "plantType",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "cropName",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "plantType",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      }
    ],
    "name": "addCrop",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "goodsId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "exp",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "phone",
        "type": "string"
      }
    ],
    "name": "addGoods",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      }
    ],
    "name": "addMaterial",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processName",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "types",
        "type": "uint256"
      }
    ],
    "name": "addProcess",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productType",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      }
    ],
    "name": "addProduct",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "signer",
        "type": "address"
      }
    ],
    "name": "checkSignUp",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "cropProcess",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "cropProcessDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      }
    ],
    "name": "finishProcess",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getAllUserInfo",
    "outputs": [
      {
        "components": [
          {
            "internalType": "uint256",
            "name": "role",
            "type": "uint256"
          },
          {
            "internalType": "uint256",
            "name": "requestRole",
            "type": "uint256"
          },
          {
            "internalType": "uint256",
            "name": "status",
            "type": "uint256"
          },
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "phone",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "note",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "userAddress",
            "type": "address"
          }
        ],
        "internalType": "struct Loan.userInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "cUser",
        "type": "address"
      }
    ],
    "name": "getUserCrops",
    "outputs": [
      {
        "components": [
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "plantType",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "cropId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "time",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "certification",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "produceAddress",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "materialId",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          }
        ],
        "internalType": "struct Loan.cropInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "gUser",
        "type": "address"
      }
    ],
    "name": "getUserGoods",
    "outputs": [
      {
        "components": [
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "certification",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "goodsId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "productId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "time",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "produceAddress",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "note",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "exp",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "phone",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          }
        ],
        "internalType": "struct Loan.goodsInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "mUser",
        "type": "address"
      }
    ],
    "name": "getUserMaterial",
    "outputs": [
      {
        "components": [
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          },
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "materialId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "certification",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "produceAddress",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "note",
            "type": "string"
          }
        ],
        "internalType": "struct Loan.materialInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "pUser",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "types",
        "type": "uint256"
      }
    ],
    "name": "getUserProcess",
    "outputs": [
      {
        "components": [
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "certification",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "processId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "productId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "time",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "produceAddress",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "note",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          }
        ],
        "internalType": "struct Loan.processInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "pUser",
        "type": "address"
      }
    ],
    "name": "getUserProduct",
    "outputs": [
      {
        "components": [
          {
            "internalType": "string",
            "name": "productId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "certification",
            "type": "string"
          },
          {
            "internalType": "uint256",
            "name": "status",
            "type": "uint256"
          },
          {
            "internalType": "string",
            "name": "cropId",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "name",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "time",
            "type": "string"
          },
          {
            "internalType": "string",
            "name": "productType",
            "type": "string"
          },
          {
            "internalType": "address",
            "name": "owner",
            "type": "address"
          }
        ],
        "internalType": "struct Loan.productInfo[]",
        "name": "",
        "type": "tuple[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "goodsDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "goodsId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "exp",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "phone",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "materialDict",
    "outputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "materialList",
    "outputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "owner",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "processDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "name": "productDict",
    "outputs": [
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "status",
        "type": "uint256"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productType",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "signer",
        "type": "address"
      }
    ],
    "name": "refuseSignUp",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "requestRole",
        "type": "uint256"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      }
    ],
    "name": "signUp",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "user",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "role",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "requestRole",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "status",
        "type": "uint256"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "phone",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "userAddress",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userCrops",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "plantType",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userGoods",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "goodsId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "exp",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "phone",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userMaterial",
    "outputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "materialId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userProcess",
    "outputs": [
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "processId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "produceAddress",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "note",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "userProduct",
    "outputs": [
      {
        "internalType": "string",
        "name": "productId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "certification",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "status",
        "type": "uint256"
      },
      {
        "internalType": "string",
        "name": "cropId",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "time",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "productType",
        "type": "string"
      },
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "userRole",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  }
]
const provider = new ethers.providers.Web3Provider(web3.currentProvider);

const signer = provider.getSigner();

const contract = new ethers.Contract(contractAddress, abi, provider);
const contractWithSigner = contract.connect(signer);

/**
 * 工具类
 */



export async function func_signUp(
  role,
  name,

) {
  return await contractWithSigner
    .signUp(
      role,
      name,
    )
    .then((res) => {
      return 0;
    })
    .catch((err) => {
      return err.code;
    });
}

export function func_checkSignUp(address) {
  console.log("check address=" + address);
  contractWithSigner
    .checkSignUp(address)
    .then((res) => {
      return 0;
    })
    .catch((err) => {
      return err.code;
    });
}
export function func_refuseSignUp(address) {
  console.log("refuse address=" + address);
  contractWithSigner
    .refuseSignUp(address)
    .then((res) => {
      return 0;
    })
    .catch((err) => {
      return err.code;
    });
}

export async function func_getAddress() {
  if (typeof window.ethereum === "undefined") {
    //没安装MetaMask钱包进行弹框提示
    console.log("请安装MetaMask");
  } else {
    try {
      let res = await ethereum.request({ method: "eth_requestAccounts" });
      return res[0];
    } catch (e) {
      console.log(e);
    }
  }
}

export function checkAddressEqual(addr1, addr2) {
  return addr1.toLowerCase() == addr2.toLowerCase();
}

export async function func_getUserInfo(address) {
  let res = await contractWithSigner.user(address);


  return res;
}

export async function func_getUserRole(address) {
  let user = await contractWithSigner.user(address);
  return Number(user.role.toString());
}





export async function func_getAllUser() {
  let data = await contractWithSigner.getAllUserInfo();

  return data;
}

export function func_addMaterial(data) {
  const {
    materialId, name, certification, produceAddress, note
  }=data
  console.log('addMaterial:',data)
  contractWithSigner.addMaterial(materialId, name, certification, produceAddress, note).then((res) => {
    console.log("res=", res);
    return 0;
  })
      .catch((err) => {
        return err.code;
      });
}

export async function func_getMaterial(address) {
  let res=await contractWithSigner.getUserMaterial(address)
  return res
}

export async function func_getMaterialById(materialId) {
  let res=await contractWithSigner.materialDict(materialId)
  return res
}

export async function func_addCrop(data) {
  const {
    cropId, cropName, materialId, plantType, time, certification, fullAddress
  }=data

  let res=await contractWithSigner.addCrop(cropId, cropName, materialId,plantType, time, certification, fullAddress)
  return res
}

export async function func_getUserCrops(peasant) {
  let data = await contractWithSigner.getUserCrops(peasant);
  return data;
}

export async function func_getCropById(cropId) {
  let res=await contractWithSigner.CropsDict(cropId)
  return res
}

export async function func_bindMaterial(mId,cId) {
  let res = await contractWithSigner.bindMaterial(mId,cId);
  return res;
}

export async function func_addProcess(data,types) {
  const {
    processId, productId, name, certification, time, note, produceAddress
  }=data
  console.log(data)
  let res=await contractWithSigner.addProcess(processId, productId, name, certification, time, note, produceAddress, types )
  return res
}

export async function func_getUserProcess(addr,types) {
  let data = await contractWithSigner.getUserProcess(addr, types);
  return data;
}

export async function func_addProduct(data) {
  const {
    productId, name, productType, cropId
  }=data
  console.log(data)
  let res=await contractWithSigner.addProduct(productId, name, productType, cropId)
  return res
}

export async function func_getUserProduct(addr) {
  let data = await contractWithSigner.getUserProduct(addr);
  return data;
}

export async function func_getProductById(productId) {
  let res=await contractWithSigner.productDict(productId)
  return res
}


export async function func_finishProcess(data) {
  const {
    productId, certification, time
  }=data
  let res = await contractWithSigner.finishProcess(productId, certification, time);
  return res;
}

export async function func_addGoods(data) {
  const {
    goodsId, productId, name, certification, exp, phone
  }=data
  console.log(data)
  let res=await contractWithSigner.addGoods(goodsId, productId, name, certification, exp, phone)
  return res
}

export async function func_getUserGoods(addr) {
  let data = await contractWithSigner.getUserGoods(addr);
  return data;
}

export async function func_getGoodsById(goodsId) {
  let res=await contractWithSigner.goodsDict(goodsId)
  return res
}

